Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bugfix: treesize integer overflows #3963

Merged
merged 2 commits into from
Jun 12, 2023
Merged

Conversation

rhafer
Copy link
Contributor

@rhafer rhafer commented Jun 12, 2023

Reading the treesize was parsing the string value as a signed integer while setting the treesize used unsigned integers this could cause failures (out of range errors) when reading very large treesizes.

This PR is mainly a workaround for scenarios where the treesize propagation would result in negative treesize, which then are stored as unsigned integers in the xattrs.

https://github.com/owncloud/enterprise/issues/5783

If updating the treesize would result in a negative new treesize,
we set the new treesize to zero.

This is a workaround for enterprise issue #5783. Until we have found
the root cause for the error in treesize propagation.
} else {
newSize = treeSize - uint64(-sizeDiff)
}
newSize = treeSize - uint64(-sizeDiff)
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this case statement makes the code harder to understand. I'd rather prefer to have it in the old if - else with an additional condition in the sizeDiff < 0 branch.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I dislike nested if/elses. I think new solution is cleaner in that regard. (just my opinion - not critical)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I also found the nested if inside the switch harder to read. Especially as I would need to add an additional if branch (or turn the nested if into a nested switch ...)

It might be more readable if I turn this into two separate switch commands though. Let me try ...

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd rather prefer to have it in the old if - else with an additional condition in the sizeDiff < 0 branch.

@dragotin Played around with this a bit. And adding another branch to the if statement will actually make the linter complain about the ifElseChain that should be turned into a switch statement ;-)

I guess I'll just leave it as is for now. (Splitting up the switch also doesn't help much with readability I think, as it will require an outer if condition. 🤷‍♂️

Copy link
Contributor

@kobergj kobergj left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me 👍

pkg/storage/utils/decomposedfs/node/node.go Show resolved Hide resolved
Previously SetTreesize stored the treesize as an unsigned 64bit integer
(converted to a string) and GetTreesize parsed that string as a signed 64bit
integer, which could lead to overflow issues.
@rhafer rhafer merged commit 5fbd21b into cs3org:edge Jun 12, 2023
@micbar micbar mentioned this pull request Jun 13, 2023
9 tasks
@phil-davis phil-davis changed the title Bugfix: treesize interger overflows Bugfix: treesize integer overflows Jun 13, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants